
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>YUI Library Examples: Widget: Extending the Base Widget Class</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    	<link rel="stylesheet" type="text/css" href="../../assets/yui.css" >

<style>
    /*Supplemental CSS for the YUI distribution*/
    #custom-doc { width: 95%; min-width: 950px; }
    #pagetitle {background-image: url(../../assets/bg_hd.gif);}
/*    #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/
</style>

<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css">
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>
<style type="text/css">
    .yui3-js-enabled .yui3-spinner-loading {
        display:none;
    }

    .yui3-spinner-hidden {
        display:none;
    }

    .yui3-spinner {
        display:-moz-inline-stack;
        display:inline-block;
        zoom:1;
        *display:inline;
        vertical-align:middle;
    }

    .yui3-spinner-content {
        padding:1px;
        position:relative;
    }

    .yui3-spinner-value {
        width:2em;
        height:1.5em;
        text-align:right;
        margin-right:22px;
        vertical-align:top;
        border:1px solid #000;
        padding:2px;
    }

    .yui3-spinner-increment, .yui3-spinner-decrement {
        position:absolute;
        height:1em;
        width:22px;
        overflow:hidden;
        text-indent:-10em;
        border:1px solid #999;
        margin:0;
        padding:0px;
    }

    .yui3-spinner-increment {
        top:1px;
        *top:2px;
        right:1px;
        background:#ddd url(assets/arrows.png) no-repeat 50% 0px;
    }

     .yui3-spinner-decrement {
        bottom:1px;
        *bottom:2px;
        right:1px;
        background:#ddd url(assets/arrows.png) no-repeat 50% -20px;
     }

    #widget-extend-example {
        padding:5px;
    }

    #widget-extend-example .hint {
        margin-top:10px;
        font-size:85%;
        color:#00a;
    }

</style>
</head>
<body id="yahoo-com" class="yui3-skin-sam  yui-skin-sam">
<div id="custom-doc" class="yui-t2">
<div id="hd">
	<div id="ygunav">
		<p>
            <em>
                <a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i>	
            </em>
		</p>
		<form action="http://search.yahoo.com/search" id="sitesearchform">
            <input name="vs" type="hidden" value="developer.yahoo.com">
            <input name="vs" type="hidden" value="yuiblog.com">
			<input name="vs" type="hidden" value="yuilibrary.com">
		    <div id="sitesearch">
		    	<label for="searchinput">Site Search (YDN, YUILibrary &amp; YUIBlog): </label>
			    <input type="text" id="searchinput" name="p">
			    <input type="submit" value="Search" id="searchsubmit" class="ygbt">
		    </div>
		</form>
    </div>
	<div id="ygma"><a href="../../"><img src="../../assets/logo.gif"  border="0" width="200" height="93"></a></div>
	<div id="pagetitle"><h1>YUI Library Examples: Widget: Extending the Base Widget Class</h1></div>
</div>
<div id="bd">


	<div id="yui-main">
		<div class="yui-b">
		  <div class="yui-ge">
			  <div class="yui-u first example" id="main">

	<h2>Widget: Extending the Base Widget Class</h2>

	<div id="example" class="promo">
	<div class="example-intro">
	This example shows how to extend the base <code>Widget</code> class to create a simple, re-usable spinner control. The <code>Spinner</code> class created in the example is not intended to be a fully featured spinner. It is used here as a concrete example, to convey some of the key concepts to keep in mind when extending the <code>Widget</code> class.
	</div>

	<div class="module example-container ">
			<div class="hd exampleHd">
			<p class="newWindowButton yui-skin-sam">
                <a href="widget-extend_clean.html" target="_blank">View example in new window.</a>
            </p>
		</div>		<div id="example-canvas" class="bd">

	
	<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

	<div id="widget-extend-example">
    A basic spinner widget: <input type="text" id="numberField" class="yui3-spinner-loading" value="20" />
    <p class="hint">Click the buttons, or the arrow up/down and page up/down keys on your keyboard to change the spinner's value</p>
</div>

<script type="text/javascript">
YUI({ filter: 'raw' }).use("event-key", "widget", function(Y) {

    var Lang = Y.Lang,
        Widget = Y.Widget,
        Node = Y.Node;

    /* Spinner class constructor */
    function Spinner(config) {
        Spinner.superclass.constructor.apply(this, arguments);
    }

    /* 
     * Required NAME static field, to identify the Widget class and 
     * used as an event prefix, to generate class names etc. (set to the 
     * class name in camel case). 
     */
    Spinner.NAME = "spinner";

    /*
     * The attribute configuration for the Spinner widget. Attributes can be
     * defined with default values, get/set functions and validator functions
     * as with any other class extending Base.
     */
    Spinner.ATTRS = {
        // The minimum value for the spinner.
        min : {
            value:0
        },

        // The maximum value for the spinner.
        max : {
            value:100
        },

        // The current value of the spinner.
        value : {
            value:0,
            validator: function(val) {
                return this._validateValue(val);
            }
        },

        // Amount to increment/decrement the spinner when the buttons or arrow up/down keys are pressed.
        minorStep : {
            value:1
        },

        // Amount to increment/decrement the spinner when the page up/down keys are pressed.
        majorStep : {
            value:10
        },

        // override default ("null"), required for focus()
        tabIndex: {
            value: 0
        },

        // The strings for the spinner UI. This attribute is 
        // defined by the base Widget class but has an empty value. The
        // spinner is simply providing a default value for the attribute.
        strings: {
            value: {
                tooltip: "Press the arrow up/down keys for minor increments, page up/down for major increments.",
                increment: "Increment",
                decrement: "Decrement"
            }
        }
    };

    /* Static constant used to identify the classname applied to the spinners value field */
    Spinner.INPUT_CLASS = Y.ClassNameManager.getClassName(Spinner.NAME, "value");

    /* Static constants used to define the markup templates used to create Spinner DOM elements */
    Spinner.INPUT_TEMPLATE = '<input type="text" class="' + Spinner.INPUT_CLASS + '">';
    Spinner.BTN_TEMPLATE = '<button type="button"></button>';

    /* 
     * The HTML_PARSER static constant is used by the Widget base class to populate 
     * the configuration for the spinner instance from markup already on the page.
     *
     * The Spinner class attempts to set the value of the spinner widget if it
     * finds the appropriate input element on the page.
     */
    Spinner.HTML_PARSER = {
        value: function (srcNode) {
            var val = parseInt(srcNode.get("value")); 
            return Y.Lang.isNumber(val) ? val : null;
        }
    };

    /* Spinner extends the base Widget class */
    Y.extend(Spinner, Widget, {

        /*
         * initializer is part of the lifecycle introduced by 
         * the Widget class. It is invoked during construction,
         * and can be used to setup instance specific state.
         * 
         * The Spinner class does not need to perform anything
         * specific in this method, but it is left in as an example.
         */
        initializer: function() {
            // Not doing anything special during initialization
        },

        /*
         * destructor is part of the lifecycle introduced by 
         * the Widget class. It is invoked during destruction,
         * and can be used to cleanup instance specific state.
         * 
         * The spinner cleans up any node references it's holding
         * onto. The Widget classes destructor will purge the 
         * widget's bounding box of event listeners, so spinner 
         * only needs to clean up listeners it attaches outside of 
         * the bounding box.
         */
        destructor : function() {
            this._documentMouseUpHandle.detach();

            this.inputNode = null;
            this.incrementNode = null;
            this.decrementNode = null;
        },

        /*
         * renderUI is part of the lifecycle introduced by the
         * Widget class. Widget's renderer method invokes:
         *
         *     renderUI()
         *     bindUI()
         *     syncUI()
         *
         * renderUI is intended to be used by the Widget subclass
         * to create or insert new elements into the DOM. 
         *
         * For spinner the method adds the input (if it's not already 
         * present in the markup), and creates the inc/dec buttons
         */
        renderUI : function() {
            this._renderInput();
            this._renderButtons();
        },

        /*
         * bindUI is intended to be used by the Widget subclass 
         * to bind any event listeners which will drive the Widget UI.
         * 
         * It will generally bind event listeners for attribute change
         * events, to update the state of the rendered UI in response 
         * to attribute value changes, and also attach any DOM events,
         * to activate the UI.
         * 
         * For spinner, the method:
         *
         * - Sets up the attribute change listener for the "value" attribute
         *
         * - Binds key listeners for the arrow/page keys
         * - Binds mouseup/down listeners on the boundingBox, document respectively.
         * - Binds a simple change listener on the input box.
         */
        bindUI : function() {
            this.after("valueChange", this._afterValueChange);

            var boundingBox = this.get("boundingBox");

            // Looking for a key event which will fire continously across browsers while the key is held down. 38, 40 = arrow up/down, 33, 34 = page up/down
            var keyEventSpec = (!Y.UA.opera) ? "down:" : "press:";
            keyEventSpec += "38, 40, 33, 34";

            Y.on("key", Y.bind(this._onDirectionKey, this), boundingBox, keyEventSpec);
            Y.on("mousedown", Y.bind(this._onMouseDown, this), boundingBox);
            this._documentMouseUpHandle = Y.on("mouseup", Y.bind(this._onDocMouseUp, this), boundingBox.get("ownerDocument"));

            Y.on("change", Y.bind(this._onInputChange, this), this.inputNode);
        },

        /*
         * syncUI is intended to be used by the Widget subclass to
         * update the UI to reflect the current state of the widget.
         * 
         * For spinner, the method sets the value of the input field,
         * to match the current state of the value attribute.
         */
        syncUI : function() {
            this._uiSetValue(this.get("value"));
        },

        /*
         * Creates the input control for the spinner and adds it to
         * the widget's content box, if not already in the markup.
         */
        _renderInput : function() {
            var contentBox = this.get("contentBox"),
                input = contentBox.one("." + Spinner.INPUT_CLASS),
                strings = this.get("strings");

            if (!input) {
                input = Node.create(Spinner.INPUT_TEMPLATE);
                contentBox.appendChild(input);
            }

            input.set("title", strings.tooltip);
            this.inputNode = input;
        },

        /*
         * Creates the button controls for the spinner and add them to
         * the widget's content box, if not already in the markup.
         */
        _renderButtons : function() {
            var contentBox = this.get("contentBox"),
                strings = this.get("strings");

            var inc = this._createButton(strings.increment, this.getClassName("increment"));
            var dec = this._createButton(strings.decrement, this.getClassName("decrement"));

            this.incrementNode = contentBox.appendChild(inc);
            this.decrementNode = contentBox.appendChild(dec);
        },

        /*
         * Utility method, to create a spinner button
         */
        _createButton : function(text, className) {

            var btn = Y.Node.create(Spinner.BTN_TEMPLATE);
            btn.set("innerHTML", text);
            btn.set("title", text);
            btn.addClass(className);

            return btn;
        },

        /*
         * Bounding box mouse down handler. Will determine if the mouse down
         * is on one of the spinner buttons, and increment/decrement the value
         * accordingly.
         * 
         * The method also sets up a timer, to support the user holding the mouse
         * down on the spinner buttons. The timer is cleared when a mouse up event
         * is detected.
         */
        _onMouseDown : function(e) {
            var node = e.target,
                dir,
                handled = false,
                currVal = this.get("value"),
                minorStep = this.get("minorStep");

            if (node.hasClass(this.getClassName("increment"))) {
                this.set("value", currVal + minorStep);
                dir = 1;
                handled = true;
            } else if (node.hasClass(this.getClassName("decrement"))) {
                this.set("value", currVal - minorStep);
                dir = -1;
                handled = true;
            }

            if (handled) {
                this._setMouseDownTimers(dir, minorStep);
            }
        },

        /*
         * Override the default content box value, since we don't want the srcNode
         * to be the content box for spinner.
         */
        _defaultCB : function() {
            return null;
        },

        /*
         * Document mouse up handler. Clears the timers supporting
         * the "mouse held down" behavior.
         */
        _onDocMouseUp : function(e) {
            this._clearMouseDownTimers();
        },

        /*
         * Bounding box Arrow up/down, Page up/down key listener.
         *
         * Increments/Decrement the spinner value, based on the key pressed.
         */
        _onDirectionKey : function(e) {

            e.preventDefault();

            var currVal = this.get("value"),
                newVal = currVal,
                minorStep = this.get("minorStep"),
                majorStep = this.get("majorStep");

            switch (e.charCode) {
                case 38:
                    newVal += minorStep;
                    break;
                case 40:
                    newVal -= minorStep;
                    break;
                case 33:
                    newVal += majorStep;
                    newVal = Math.min(newVal, this.get("max"));
                    break;
                case 34:
                    newVal -= majorStep;
                    newVal = Math.max(newVal, this.get("min"));
                    break;
            }

            if (newVal !== currVal) {
                this.set("value", newVal);
            }
        },

        /*
         * Simple change handler, to make sure user does not input an invalid value
         */
        _onInputChange : function(e) {
            if (!this._validateValue(this.inputNode.get("value"))) {
                this.syncUI();
            }
        },

        /*
         * Initiates mouse down timers, to increment slider, while mouse button
         * is held down
         */
        _setMouseDownTimers : function(dir, step) {
            this._mouseDownTimer = Y.later(500, this, function() {
                this._mousePressTimer = Y.later(100, this, function() {
                    this.set("value", this.get("value") + (dir * step));
                }, null, true)
            });
        },

        /*
         * Clears timers used to support the "mouse held down" behavior
         */
        _clearMouseDownTimers : function() {
            if (this._mouseDownTimer) {
                this._mouseDownTimer.cancel();
                this._mouseDownTimer = null;
            }
            if (this._mousePressTimer) {
                this._mousePressTimer.cancel();
                this._mousePressTimer = null;
            }
        },

        /*
         * value attribute change listener. Updates the 
         * value in the rendered input box, whenever the 
         * attribute value changes.
         */
        _afterValueChange : function(e) {
            this._uiSetValue(e.newVal);
        },

        /*
         * Updates the value of the input box to reflect 
         * the value passed in
         */
        _uiSetValue : function(val) {
            this.inputNode.set("value", val);
        },

        /*
         * value attribute default validator. Verifies that
         * the value being set lies between the min/max value
         */
        _validateValue: function(val) {
            var min = this.get("min"),
                max = this.get("max");

            return (Lang.isNumber(val) && val >= min && val <= max);
        }
    });

    // Create a new Spinner instance, drawing it's 
    // starting value from an input field already on the 
    // page (the #numberField text box)
    var spinner = new Spinner({
        srcNode: "#numberField",
        max:100,
        min:0
    });
    spinner.render();
    spinner.focus();
});
</script>

	<!--END SOURCE CODE FOR EXAMPLE =============================== -->

	
		</div>
	</div>
	</div>

	<h3>Extending The <code>Widget</code> Class</h3>

<h4>Basic Class Structure</h4>

<p>Widgets classes follow the general pattern implemented by the <code>Spinner</code> class, shown in the code snippet below. The basic pattern for setting up a new widget class involves:</p>

<ol>
    <li>Defining the constructor function for the new widget class, which invokes the superclass constructor to kick off the initialization chain <em>(line 2)</em></li>
    <li>Defining the static <code>NAME</code> property for the class, which is normally the class name in camel case, and is used to prefix events and CSS classes fired/created by the class <em>(line 11)</em></li>
    <li>Defining the static <code>ATTRS</code> property for the class, which defines the set of attributes which the class will introduce, in addition to the superclass attributes <em>(line 18-57)</em></li>
    <li>Extending the <code>Widget</code> class, and adding/overriding any prototype properties/methods <em>(line 61)</em></li>
</ol>

<div id="syntax-2e656c9943a81542d2dc805a9a18d5cd" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/* Spinner class constructor */</span></div></li><li class="li1"><div class="de1"><span class="kw2">function</span> Spinner<span class="br0">&#40;</span>config<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    Spinner.<span class="me1">superclass</span>.<span class="me1">constructor</span>.<span class="me1">apply</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> arguments<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/* </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Required NAME static field, to identify the Widget class and </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* used as an event prefix, to generate class names etc. (set to the </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* class name in camel case). </span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">Spinner.<span class="kw3">NAME</span> <span class="sy0">=</span> <span class="st0">&quot;spinner&quot;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* The attribute configuration for the Spinner widget. Attributes can be</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* defined with default values, get/set functions and validator functions</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* as with any other class extending Base.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">Spinner.<span class="me1">ATTRS</span> <span class="sy0">=</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">// The minimum value for the spinner.</span></div></li><li class="li2"><div class="de2">    min <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        value<span class="sy0">:</span><span class="nu0">0</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// The maximum value for the spinner.</span></div></li><li class="li2"><div class="de2">    max <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        value<span class="sy0">:</span><span class="nu0">100</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// The current value of the spinner.</span></div></li><li class="li2"><div class="de2">    value <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        value<span class="sy0">:</span><span class="nu0">0</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">        validator<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            <span class="kw1">return</span> <span class="kw1">this</span>._validateValue<span class="br0">&#40;</span>val<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// Amount to increment/decrement the spinner when the buttons, </span></div></li><li class="li1"><div class="de1">    <span class="co1">// or arrow up/down keys are pressed.</span></div></li><li class="li1"><div class="de1">    minorStep <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">        value<span class="sy0">:</span><span class="nu0">1</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// Amount to increment/decrement the spinner when the page up/down keys are pressed.</span></div></li><li class="li1"><div class="de1">    majorStep <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">        value<span class="sy0">:</span><span class="nu0">10</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// The localizable strings for the spinner. This attribute is </span></div></li><li class="li1"><div class="de1">    <span class="co1">// defined by the base Widget class but has an empty value. The</span></div></li><li class="li2"><div class="de2">    <span class="co1">// spinner is simply providing a default value for the attribute.</span></div></li><li class="li1"><div class="de1">    strings<span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        value<span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            tooltip<span class="sy0">:</span> <span class="st0">&quot;Press the arrow up/down keys for minor increments, <span class="es0">\ </span></span></div></li><li class="li1"><div class="de1"><span class="st0">                      page up/down for major increments.&quot;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">            increment<span class="sy0">:</span> <span class="st0">&quot;Increment&quot;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">            decrement<span class="sy0">:</span> <span class="st0">&quot;Decrement&quot;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">Y.<span class="me1">extend</span><span class="br0">&#40;</span>Spinner<span class="sy0">,</span> Widget<span class="sy0">,</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">// Methods/properties to add to the prototype of the new class</span></div></li><li class="li1"><div class="de1">    ...</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/* Spinner class constructor */</span>
<span class="kw2">function</span> Spinner<span class="br0">&#40;</span>config<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    Spinner.<span class="me1">superclass</span>.<span class="me1">constructor</span>.<span class="me1">apply</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> arguments<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/* 
 * Required NAME static field, to identify the Widget class and 
 * used as an event prefix, to generate class names etc. (set to the 
 * class name in camel case). 
 */</span>
Spinner.<span class="kw3">NAME</span> <span class="sy0">=</span> <span class="st0">&quot;spinner&quot;</span><span class="sy0">;</span>
&nbsp;
<span class="coMULTI">/*
 * The attribute configuration for the Spinner widget. Attributes can be
 * defined with default values, get/set functions and validator functions
 * as with any other class extending Base.
 */</span>
Spinner.<span class="me1">ATTRS</span> <span class="sy0">=</span> <span class="br0">&#123;</span>
    <span class="co1">// The minimum value for the spinner.</span>
    min <span class="sy0">:</span> <span class="br0">&#123;</span>
        value<span class="sy0">:</span><span class="nu0">0</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="co1">// The maximum value for the spinner.</span>
    max <span class="sy0">:</span> <span class="br0">&#123;</span>
        value<span class="sy0">:</span><span class="nu0">100</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="co1">// The current value of the spinner.</span>
    value <span class="sy0">:</span> <span class="br0">&#123;</span>
        value<span class="sy0">:</span><span class="nu0">0</span><span class="sy0">,</span>
        validator<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw1">return</span> <span class="kw1">this</span>._validateValue<span class="br0">&#40;</span>val<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="co1">// Amount to increment/decrement the spinner when the buttons, </span>
    <span class="co1">// or arrow up/down keys are pressed.</span>
    minorStep <span class="sy0">:</span> <span class="br0">&#123;</span>
        value<span class="sy0">:</span><span class="nu0">1</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="co1">// Amount to increment/decrement the spinner when the page up/down keys are pressed.</span>
    majorStep <span class="sy0">:</span> <span class="br0">&#123;</span>
        value<span class="sy0">:</span><span class="nu0">10</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="co1">// The localizable strings for the spinner. This attribute is </span>
    <span class="co1">// defined by the base Widget class but has an empty value. The</span>
    <span class="co1">// spinner is simply providing a default value for the attribute.</span>
    strings<span class="sy0">:</span> <span class="br0">&#123;</span>
        value<span class="sy0">:</span> <span class="br0">&#123;</span>
            tooltip<span class="sy0">:</span> <span class="st0">&quot;Press the arrow up/down keys for minor increments, <span class="es0">\ </span>
                      page up/down for major increments.&quot;</span><span class="sy0">,</span>
            increment<span class="sy0">:</span> <span class="st0">&quot;Increment&quot;</span><span class="sy0">,</span>
            decrement<span class="sy0">:</span> <span class="st0">&quot;Decrement&quot;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
Y.<span class="me1">extend</span><span class="br0">&#40;</span>Spinner<span class="sy0">,</span> Widget<span class="sy0">,</span> <span class="br0">&#123;</span>
    <span class="co1">// Methods/properties to add to the prototype of the new class</span>
    ...
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-2e656c9943a81542d2dc805a9a18d5cd-plain">/* Spinner class constructor */
function Spinner(config) {
    Spinner.superclass.constructor.apply(this, arguments);
}

/* 
 * Required NAME static field, to identify the Widget class and 
 * used as an event prefix, to generate class names etc. (set to the 
 * class name in camel case). 
 */
Spinner.NAME = "spinner";

/*
 * The attribute configuration for the Spinner widget. Attributes can be
 * defined with default values, get/set functions and validator functions
 * as with any other class extending Base.
 */
Spinner.ATTRS = {
    // The minimum value for the spinner.
    min : {
        value:0
    },

    // The maximum value for the spinner.
    max : {
        value:100
    },

    // The current value of the spinner.
    value : {
        value:0,
        validator: function(val) {
            return this._validateValue(val);
        }
    },

    // Amount to increment/decrement the spinner when the buttons, 
    // or arrow up/down keys are pressed.
    minorStep : {
        value:1
    },

    // Amount to increment/decrement the spinner when the page up/down keys are pressed.
    majorStep : {
        value:10
    },

    // The localizable strings for the spinner. This attribute is 
    // defined by the base Widget class but has an empty value. The
    // spinner is simply providing a default value for the attribute.
    strings: {
        value: {
            tooltip: "Press the arrow up/down keys for minor increments, \ 
                      page up/down for major increments.",
            increment: "Increment",
            decrement: "Decrement"
        }
    }
};

Y.extend(Spinner, Widget, {
    // Methods/properties to add to the prototype of the new class
    ...
});</textarea></div>
<p>Note that these steps are the same for any class which is derived from <a href="http://developer.yahoo.com/yui/3/base/"><code>Base</code></a>, nothing Widget-specific is involved yet. 
Widget adds the concept of a rendered UI to the existing Base lifecycle (viz. init, destroy and attribute state configuration), which we'll see show up in Widget-specific areas below.</p>

<h4>The HTML_PARSER Property</h4>

<p>
The first Widget-specific property <code>Spinner</code> implements is the static <a href="../../api/Widget.html#property_Widget.HTML_PARSER"><code>HTML_PARSER</code></a> property. It is used to set the initial widget configuration based on markup, providing basic progressive enhancement support.
</p>
<p> 
The value of the <code>HTML_PARSER</code> property is an object literal, where each property is a widget attribute name, and the value is either a selector string (if the attribute is a node reference) or a function which is executed to provide 
a value for the attribute from the markup on the page. Markup is essentially thought of as an additional data source for the user to set initial attribute values, outside of the configuration object passed to the constructor 
<em>(values passed to the constructor will take precedence over values picked up from markup)</em>.
</p>

<p>For <code>Spinner</code>, <code>HTML_PARSER</code> defines a function for the <code>value</code> attribute, which sets the initial value of the spinner based on an input field if present in the markup.</p>

<div id="syntax-710ed9d4fd39fd657c829cc878d90015" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/* </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* The HTML_PARSER static constant is used by the Widget base class to populate </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the configuration for the spinner instance from markup already on the page.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* The Spinner class attempts to set the value of the spinner widget if it</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* finds the appropriate input element on the page.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">Spinner.<span class="me1">HTML_PARSER</span> <span class="sy0">=</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    value<span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>contentBox<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">        <span class="kw2">var</span> node <span class="sy0">=</span> contentBox.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span> <span class="sy0">+</span> Spinner.<span class="me1">INPUT_CLASS</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">return</span> <span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="sy0">?</span> parseInt<span class="br0">&#40;</span>node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw2">null</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/* 
 * The HTML_PARSER static constant is used by the Widget base class to populate 
 * the configuration for the spinner instance from markup already on the page.
 *
 * The Spinner class attempts to set the value of the spinner widget if it
 * finds the appropriate input element on the page.
 */</span>
Spinner.<span class="me1">HTML_PARSER</span> <span class="sy0">=</span> <span class="br0">&#123;</span>
    value<span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>contentBox<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">var</span> node <span class="sy0">=</span> contentBox.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span> <span class="sy0">+</span> Spinner.<span class="me1">INPUT_CLASS</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw1">return</span> <span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="sy0">?</span> parseInt<span class="br0">&#40;</span>node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw2">null</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">;</span></pre></div><textarea id="syntax-710ed9d4fd39fd657c829cc878d90015-plain">/* 
 * The HTML_PARSER static constant is used by the Widget base class to populate 
 * the configuration for the spinner instance from markup already on the page.
 *
 * The Spinner class attempts to set the value of the spinner widget if it
 * finds the appropriate input element on the page.
 */
Spinner.HTML_PARSER = {
    value: function (contentBox) {
        var node = contentBox.one("." + Spinner.INPUT_CLASS);
        return (node) ? parseInt(node.get("value")) : null;
    }
};</textarea></div>
<h4>Lifecycle Methods: initializer, destructor</h4>

<p>The <code>initializer</code> and <code>destructor</code> lifecycle methods are carried over from <code>Base</code>, and can be used to set up initial state during construction, and clean up state during destruction respectively.</p>

<p>For <code>Spinner</code>, there is nothing special we need to do in the <code>initializer</code> (attribute setup is already taken care of), but it's left in the example to round out the lifecycle discussion.</p>

<p>The <code>destructor</code> takes care of detaching any event listeners <code>Spinner</code> adds outside of the bounding box (event listeners on/inside the bounding box are purged by <code>Widget</code>'s <code>destructor</code>).</p>

<div id="syntax-e6c753ccf61e9bc46d3c3cb87ee7ac0b" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* initializer is part of the lifecycle introduced by </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the Widget class. It is invoked during construction,</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* and can be used to set up instance specific state.</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;*  </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* The Spinner class does not need to perform anything</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* specific in this method, but it is left in as an example.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">initializer<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>config<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    <span class="co1">// Not doing anything special during initialization</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* destructor is part of the lifecycle introduced by </span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* the Widget class. It is invoked during destruction,</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* and can be used to clean up instance specific state.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* The spinner cleans up any node references it's holding</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* onto. The Widget classes destructor will purge the </span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* widget's bounding box of event listeners, so spinner </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* only needs to clean up listeners it attaches outside of </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the bounding box.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">destructor <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    <span class="kw1">this</span>._documentMouseUpHandle.<span class="me1">detach</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>.<span class="me1">inputNode</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>.<span class="me1">incrementNode</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>.<span class="me1">decrementNode</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2"><span class="br0">&#125;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/*
 * initializer is part of the lifecycle introduced by 
 * the Widget class. It is invoked during construction,
 * and can be used to set up instance specific state.
 *  
 * The Spinner class does not need to perform anything
 * specific in this method, but it is left in as an example.
 */</span>
initializer<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>config<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">// Not doing anything special during initialization</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * destructor is part of the lifecycle introduced by 
 * the Widget class. It is invoked during destruction,
 * and can be used to clean up instance specific state.
 * 
 * The spinner cleans up any node references it's holding
 * onto. The Widget classes destructor will purge the 
 * widget's bounding box of event listeners, so spinner 
 * only needs to clean up listeners it attaches outside of 
 * the bounding box.
 */</span>
destructor <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>._documentMouseUpHandle.<span class="me1">detach</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">this</span>.<span class="me1">inputNode</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">incrementNode</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">decrementNode</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div><textarea id="syntax-e6c753ccf61e9bc46d3c3cb87ee7ac0b-plain">/*
 * initializer is part of the lifecycle introduced by 
 * the Widget class. It is invoked during construction,
 * and can be used to set up instance specific state.
 *  
 * The Spinner class does not need to perform anything
 * specific in this method, but it is left in as an example.
 */
initializer: function(config) {
    // Not doing anything special during initialization
},

/*
 * destructor is part of the lifecycle introduced by 
 * the Widget class. It is invoked during destruction,
 * and can be used to clean up instance specific state.
 * 
 * The spinner cleans up any node references it's holding
 * onto. The Widget classes destructor will purge the 
 * widget's bounding box of event listeners, so spinner 
 * only needs to clean up listeners it attaches outside of 
 * the bounding box.
 */
destructor : function() {
    this._documentMouseUpHandle.detach();

    this.inputNode = null;
    this.incrementNode = null;
    this.decrementNode = null;
}</textarea></div>
<h4>Rendering Lifecycle Methods: renderer, renderUI, bindUI, syncUI</h4>

<p>Widget adds a <code>render</code> method to the <code>init</code> and <code>destroy</code> lifecycle methods provided by Base. The <code>init</code> and <code>destroy</code> methods invoke the corresponding <code>initializer</code> and <code>destructor</code> implementations for the widget. Similarly, the <code>render</code> method invokes the <code>renderer</code> implementation for the widget. Note that the <code>renderer</code> method is not chained automatically, unlike the <code>initializer</code> and <code>destructor</code> methods.</p>

<p>The <code>Widget</code> class already provides a default <code>renderer</code> implementation, which invokes the following abstract methods in the order shown <em>(with their respective responsibilities)</em>:</p>

<ol>
    <li><code>renderUI()</code> : responsible for creating/adding elements to the DOM to render the widget.</li>
    <li><code>bindUI()</code> : responsible for binding event listeners (both attribute change and DOM event listeners) to 'activate' the rendered UI.</li>
    <li><code>syncUI()</code> : responsible for updating the rendered UI based on the current state of the widget.</li>
</ol>

<p>Since the <code>Spinner</code> class has no need to modify the <code>Widget</code> <code>renderer</code> implementation, it simply implements the above 3 methods to handle the render phase:</p>

<div id="syntax-0f631121de072d2b7f9f48e73f4f1525" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* For spinner the method adds the input (if it's not already </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* present in the markup), and creates the increment/decrement buttons</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li2"><div class="de2">renderUI <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>._renderInput<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>._renderButtons<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* For spinner, the method:</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* - Sets up the attribute change listener for the &quot;value&quot; attribute</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* - Binds key listeners for the arrow/page keys</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* - Binds mouseup/down listeners on the boundingBox, document respectively.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* - Binds a simple change listener on the input box.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">bindUI <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    <span class="kw1">this</span>.<span class="me1">after</span><span class="br0">&#40;</span><span class="st0">&quot;valueChange&quot;</span><span class="sy0">,</span> <span class="kw1">this</span>._afterValueChange<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> boundingBox <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;boundingBox&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// Looking for a key event which will fire continuously across browsers </span></div></li><li class="li2"><div class="de2">    <span class="co1">// while the key is held down. 38, 40 = arrow up/down, 33, 34 = page up/down</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> keyEventSpec <span class="sy0">=</span> <span class="br0">&#40;</span><span class="sy0">!</span>Y.<span class="me1">UA</span>.<span class="me1">opera</span><span class="br0">&#41;</span> <span class="sy0">?</span> <span class="st0">&quot;down:&quot;</span> <span class="sy0">:</span> <span class="st0">&quot;press:&quot;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    keyEventSpec <span class="sy0">+=</span> <span class="st0">&quot;38, 40, 33, 34&quot;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;change&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onInputChange<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">inputNode</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;key&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onDirectionKey<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> boundingBox<span class="sy0">,</span> keyEventSpec<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;mousedown&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onMouseDown<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> boundingBox<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>._documentMouseUpHandle <span class="sy0">=</span> Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;mouseup&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onDocMouseUp<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> </div></li><li class="li1"><div class="de1">                boundingBox.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;ownerDocument&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* For spinner, the method sets the value of the input field,</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* to match the current state of the value attribute.</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">syncUI <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>._uiSetValue<span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/*
 * For spinner the method adds the input (if it's not already 
 * present in the markup), and creates the increment/decrement buttons
 */</span>
renderUI <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>._renderInput<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">this</span>._renderButtons<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * For spinner, the method:
 *
 * - Sets up the attribute change listener for the &quot;value&quot; attribute
 *
 * - Binds key listeners for the arrow/page keys
 * - Binds mouseup/down listeners on the boundingBox, document respectively.
 * - Binds a simple change listener on the input box.
 */</span>
bindUI <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>.<span class="me1">after</span><span class="br0">&#40;</span><span class="st0">&quot;valueChange&quot;</span><span class="sy0">,</span> <span class="kw1">this</span>._afterValueChange<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw2">var</span> boundingBox <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;boundingBox&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="co1">// Looking for a key event which will fire continuously across browsers </span>
    <span class="co1">// while the key is held down. 38, 40 = arrow up/down, 33, 34 = page up/down</span>
    <span class="kw2">var</span> keyEventSpec <span class="sy0">=</span> <span class="br0">&#40;</span><span class="sy0">!</span>Y.<span class="me1">UA</span>.<span class="me1">opera</span><span class="br0">&#41;</span> <span class="sy0">?</span> <span class="st0">&quot;down:&quot;</span> <span class="sy0">:</span> <span class="st0">&quot;press:&quot;</span><span class="sy0">;</span>
    keyEventSpec <span class="sy0">+=</span> <span class="st0">&quot;38, 40, 33, 34&quot;</span><span class="sy0">;</span>
&nbsp;
&nbsp;
    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;change&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onInputChange<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">inputNode</span><span class="br0">&#41;</span><span class="sy0">;</span>
    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;key&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onDirectionKey<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> boundingBox<span class="sy0">,</span> keyEventSpec<span class="br0">&#41;</span><span class="sy0">;</span>
    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;mousedown&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onMouseDown<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> boundingBox<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">this</span>._documentMouseUpHandle <span class="sy0">=</span> Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">&quot;mouseup&quot;</span><span class="sy0">,</span> Y.<span class="me1">bind</span><span class="br0">&#40;</span><span class="kw1">this</span>._onDocMouseUp<span class="sy0">,</span> <span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">,</span> 
                boundingBox.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;ownerDocument&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * For spinner, the method sets the value of the input field,
 * to match the current state of the value attribute.
 */</span>
syncUI <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>._uiSetValue<span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div><textarea id="syntax-0f631121de072d2b7f9f48e73f4f1525-plain">/*
 * For spinner the method adds the input (if it's not already 
 * present in the markup), and creates the increment/decrement buttons
 */
renderUI : function() {
    this._renderInput();
    this._renderButtons();
},

/*
 * For spinner, the method:
 *
 * - Sets up the attribute change listener for the "value" attribute
 *
 * - Binds key listeners for the arrow/page keys
 * - Binds mouseup/down listeners on the boundingBox, document respectively.
 * - Binds a simple change listener on the input box.
 */
bindUI : function() {
    this.after("valueChange", this._afterValueChange);

    var boundingBox = this.get("boundingBox");

    // Looking for a key event which will fire continuously across browsers 
    // while the key is held down. 38, 40 = arrow up/down, 33, 34 = page up/down
    var keyEventSpec = (!Y.UA.opera) ? "down:" : "press:";
    keyEventSpec += "38, 40, 33, 34";


    Y.on("change", Y.bind(this._onInputChange, this), this.inputNode);
    Y.on("key", Y.bind(this._onDirectionKey, this), boundingBox, keyEventSpec);
    Y.on("mousedown", Y.bind(this._onMouseDown, this), boundingBox);
    this._documentMouseUpHandle = Y.on("mouseup", Y.bind(this._onDocMouseUp, this), 
                boundingBox.get("ownerDocument"));
},

/*
 * For spinner, the method sets the value of the input field,
 * to match the current state of the value attribute.
 */
syncUI : function() {
    this._uiSetValue(this.get("value"));
}</textarea></div>
<h5>A Note On Key Event Listeners</h5>

<p>The <code>Spinner</code> uses Event's <code>"key"</code> support, to set up a listener for arrow up/down and page up/down keys on the spinner's bounding box (line 31).</p>

<p>Event's <code>"key"</code> support allows <code>Spinner</code> to define a single listener, which is only invoked for the key specification provided. The key specification in the above use case is <code>"down:38, 40, 33, 34"</code> for most browsers, indicating that 
the <code>_onDirectionKey</code> method should only be called if the bounding box receives a keydown event with a character code which is either 38, 40, 33 or 34. <code>"key"</code> specifications can also contain more <a href="../../api/YUI.html#event_key">advanced filter criteria</a>, involving modifiers such as CTRL and SHIFT.</p>

<p>For the Spinner widget, we're looking for a key event which fires repeatedly while the key is held down. This differs for Opera, so we need to fork for the key event we're interested in. Future versions of <code>"key"</code> support will aim to provide this type of higher level cross-browser abstraction also.</p>

<h4>Attribute Supporting Methods</h4>

<p>Since all widgets are attribute-driven, they all follow a pretty similar pattern when it comes to how those attributes are used. For a given attribute, widgets will generally have:</p>
<ul>
    <li>A prototype method to listen for changes in the attribute</li>
    <li>A prototype method to update the state of the rendered UI, to reflect the value of an attribute.</li>
    <li>A prototype method used to set/get/validate the attribute.</li>
</ul>

<p>These methods are kept on the prototype to facilitate customization at any of the levels - event handling, ui updates, set/get/validation logic.</p>

<p>For <code>Spinner</code>, these corresponding methods for the <code>value</code> attribute are: <code>_afterValueChange</code>, <code>_uiSetValue</code> and <code>_validateValue</code>:</p>

<div id="syntax-5be61c779ffe74270885a7f6a8cdad38" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* value attribute change listener. Updates the </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* value in the rendered input box, whenever the </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* attribute value changes.</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_afterValueChange <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>._uiSetValue<span class="br0">&#40;</span>e.<span class="me1">newVal</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Updates the value of the input box to reflect </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the value passed in</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_uiSetValue <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    <span class="kw1">this</span>.<span class="me1">inputNode</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> val<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* value attribute default validator. Verifies that</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* the value being set lies between the min/max value</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_validateValue<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> min <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;min&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">        max <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;max&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw1">return</span> <span class="br0">&#40;</span>Lang.<span class="me1">isNumber</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> val <span class="sy0">&gt;=</span> min <span class="sy0">&amp;&amp;</span> val <span class="sy0">&lt;=</span> max<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/*
 * value attribute change listener. Updates the 
 * value in the rendered input box, whenever the 
 * attribute value changes.
 */</span>
_afterValueChange <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>._uiSetValue<span class="br0">&#40;</span>e.<span class="me1">newVal</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * Updates the value of the input box to reflect 
 * the value passed in
 */</span>
_uiSetValue <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>.<span class="me1">inputNode</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> val<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * value attribute default validator. Verifies that
 * the value being set lies between the min/max value
 */</span>
_validateValue<span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> min <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;min&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>
        max <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;max&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">return</span> <span class="br0">&#40;</span>Lang.<span class="me1">isNumber</span><span class="br0">&#40;</span>val<span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> val <span class="sy0">&gt;=</span> min <span class="sy0">&amp;&amp;</span> val <span class="sy0">&lt;=</span> max<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div><textarea id="syntax-5be61c779ffe74270885a7f6a8cdad38-plain">/*
 * value attribute change listener. Updates the 
 * value in the rendered input box, whenever the 
 * attribute value changes.
 */
_afterValueChange : function(e) {
    this._uiSetValue(e.newVal);
},

/*
 * Updates the value of the input box to reflect 
 * the value passed in
 */
_uiSetValue : function(val) {
    this.inputNode.set("value", val);
},

/*
 * value attribute default validator. Verifies that
 * the value being set lies between the min/max value
 */
_validateValue: function(val) {
    var min = this.get("min"),
        max = this.get("max");

    return (Lang.isNumber(val) && val >= min && val <= max);
}</textarea></div>
<p>Since this example focuses on general patterns for widget development, validator/set/get functions are not defined for attributes such as min/max in the interests of keeping the example simple, but could be, in a production ready spinner.</p>

<h4>Rendering Support Methods</h4>

<p><code>Spinner</code>'s <code>renderUI</code> method hands off creation of the input field and buttons to the following helpers which use markup templates to generate node instances:</p>

<div id="syntax-be570f1d7e3883c8bada90d1492c6075" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Creates the input field for the spinner and adds it to</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the widget's content box, if not already in the markup.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li2"><div class="de2">_renderInput <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> contentBox <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;contentBox&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">        input <span class="sy0">=</span> contentBox.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span> <span class="sy0">+</span> Spinner.<span class="me1">INPUT_CLASS</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">        strings <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;strings&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>input<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        input <span class="sy0">=</span> Node.<span class="me1">create</span><span class="br0">&#40;</span>Spinner.<span class="me1">INPUT_TEMPLATE</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        contentBox.<span class="me1">appendChild</span><span class="br0">&#40;</span>input<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    input.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;title&quot;</span><span class="sy0">,</span> strings.<span class="me1">tooltip</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>.<span class="me1">inputNode</span> <span class="sy0">=</span> input<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* Creates the button controls for the spinner and adds them to</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the widget's content box, if not already in the markup.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_renderButtons <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> contentBox <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;contentBox&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">        strings <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;strings&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> inc <span class="sy0">=</span> <span class="kw1">this</span>._createButton<span class="br0">&#40;</span>strings.<span class="me1">increment</span><span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;increment&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> dec <span class="sy0">=</span> <span class="kw1">this</span>._createButton<span class="br0">&#40;</span>strings.<span class="me1">decrement</span><span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;decrement&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    <span class="kw1">this</span>.<span class="me1">incrementNode</span> <span class="sy0">=</span> contentBox.<span class="me1">appendChild</span><span class="br0">&#40;</span>inc<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>.<span class="me1">decrementNode</span> <span class="sy0">=</span> contentBox.<span class="me1">appendChild</span><span class="br0">&#40;</span>dec<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* Utility method, to create a spinner button</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_createButton <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>text<span class="sy0">,</span> className<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> btn <span class="sy0">=</span> Y.<span class="me1">Node</span>.<span class="me1">create</span><span class="br0">&#40;</span>Spinner.<span class="me1">BTN_TEMPLATE</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    btn.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;innerHTML&quot;</span><span class="sy0">,</span> text<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    btn.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;title&quot;</span><span class="sy0">,</span> text<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    btn.<span class="me1">addClass</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw1">return</span> btn<span class="sy0">;</span></div></li><li class="li2"><div class="de2"><span class="br0">&#125;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/*
 * Creates the input field for the spinner and adds it to
 * the widget's content box, if not already in the markup.
 */</span>
_renderInput <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> contentBox <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;contentBox&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>
        input <span class="sy0">=</span> contentBox.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span> <span class="sy0">+</span> Spinner.<span class="me1">INPUT_CLASS</span><span class="br0">&#41;</span><span class="sy0">,</span>
        strings <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;strings&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>input<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        input <span class="sy0">=</span> Node.<span class="me1">create</span><span class="br0">&#40;</span>Spinner.<span class="me1">INPUT_TEMPLATE</span><span class="br0">&#41;</span><span class="sy0">;</span>
        contentBox.<span class="me1">appendChild</span><span class="br0">&#40;</span>input<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    input.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;title&quot;</span><span class="sy0">,</span> strings.<span class="me1">tooltip</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">inputNode</span> <span class="sy0">=</span> input<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * Creates the button controls for the spinner and adds them to
 * the widget's content box, if not already in the markup.
 */</span>
_renderButtons <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> contentBox <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;contentBox&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>
        strings <span class="sy0">=</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;strings&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw2">var</span> inc <span class="sy0">=</span> <span class="kw1">this</span>._createButton<span class="br0">&#40;</span>strings.<span class="me1">increment</span><span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;increment&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw2">var</span> dec <span class="sy0">=</span> <span class="kw1">this</span>._createButton<span class="br0">&#40;</span>strings.<span class="me1">decrement</span><span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;decrement&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">this</span>.<span class="me1">incrementNode</span> <span class="sy0">=</span> contentBox.<span class="me1">appendChild</span><span class="br0">&#40;</span>inc<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">this</span>.<span class="me1">decrementNode</span> <span class="sy0">=</span> contentBox.<span class="me1">appendChild</span><span class="br0">&#40;</span>dec<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * Utility method, to create a spinner button
 */</span>
_createButton <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>text<span class="sy0">,</span> className<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
    <span class="kw2">var</span> btn <span class="sy0">=</span> Y.<span class="me1">Node</span>.<span class="me1">create</span><span class="br0">&#40;</span>Spinner.<span class="me1">BTN_TEMPLATE</span><span class="br0">&#41;</span><span class="sy0">;</span>
    btn.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;innerHTML&quot;</span><span class="sy0">,</span> text<span class="br0">&#41;</span><span class="sy0">;</span>
    btn.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;title&quot;</span><span class="sy0">,</span> text<span class="br0">&#41;</span><span class="sy0">;</span>
    btn.<span class="me1">addClass</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">return</span> btn<span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div><textarea id="syntax-be570f1d7e3883c8bada90d1492c6075-plain">/*
 * Creates the input field for the spinner and adds it to
 * the widget's content box, if not already in the markup.
 */
_renderInput : function() {
    var contentBox = this.get("contentBox"),
        input = contentBox.one("." + Spinner.INPUT_CLASS),
        strings = this.get("strings");

    if (!input) {
        input = Node.create(Spinner.INPUT_TEMPLATE);
        contentBox.appendChild(input);
    }

    input.set("title", strings.tooltip);
    this.inputNode = input;
},

/*
 * Creates the button controls for the spinner and adds them to
 * the widget's content box, if not already in the markup.
 */
_renderButtons : function() {
    var contentBox = this.get("contentBox"),
        strings = this.get("strings");

    var inc = this._createButton(strings.increment, this.getClassName("increment"));
    var dec = this._createButton(strings.decrement, this.getClassName("decrement"));

    this.incrementNode = contentBox.appendChild(inc);
    this.decrementNode = contentBox.appendChild(dec);
},

/*
 * Utility method, to create a spinner button
 */
_createButton : function(text, className) {

    var btn = Y.Node.create(Spinner.BTN_TEMPLATE);
    btn.set("innerHTML", text);
    btn.set("title", text);
    btn.addClass(className);

    return btn;
}</textarea></div>
<h4>DOM Event Listeners</h4>

<p>The DOM event listeners attached during <code>bindUI</code> are straightforward event listeners, which receive the event facade for the DOM event, and update the spinner state accordingly.</p>

<p>A couple of interesting points worth noting: In the <code>"key"</code> listener we set up, we can call <code>e.preventDefault()</code> without having to check the character code, since the <code>"key"</code> event specifier will only invoke the listener 
if one of the specified keys is pressed (arrow/page up/down)</p>

<p>Also, to allow the spinner to update its value while the mouse button is held down, we set up a timer, which gets cleared out when we receive a mouseup event on the document.</p>

<div id="syntax-9a5761a8b5a3c5922607c033163c31b4" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Bounding box Arrow up/down, Page up/down key listener.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Increments/Decrements the spinner value, based on the key pressed.</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_onDirectionKey <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    e.<span class="me1">preventDefault</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    ...</div></li><li class="li1"><div class="de1">    <span class="kw1">switch</span> <span class="br0">&#40;</span>e.<span class="me1">charCode</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">        <span class="kw1">case</span> <span class="nu0">38</span><span class="sy0">:</span></div></li><li class="li1"><div class="de1">            newVal <span class="sy0">+=</span> minorStep<span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="kw1">break</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">case</span> <span class="nu0">40</span><span class="sy0">:</span></div></li><li class="li1"><div class="de1">            newVal <span class="sy0">-=</span> minorStep<span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="kw1">break</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">case</span> <span class="nu0">33</span><span class="sy0">:</span></div></li><li class="li1"><div class="de1">            newVal <span class="sy0">+=</span> majorStep<span class="sy0">;</span></div></li><li class="li1"><div class="de1">            newVal <span class="sy0">=</span> Math.<span class="me1">min</span><span class="br0">&#40;</span>newVal<span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;max&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="kw1">break</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        <span class="kw1">case</span> <span class="nu0">34</span><span class="sy0">:</span></div></li><li class="li1"><div class="de1">            newVal <span class="sy0">-=</span> majorStep<span class="sy0">;</span></div></li><li class="li1"><div class="de1">            newVal <span class="sy0">=</span> Math.<span class="me1">max</span><span class="br0">&#40;</span>newVal<span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;min&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="kw1">break</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw1">if</span> <span class="br0">&#40;</span>newVal <span class="sy0">!==</span> currVal<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> newVal<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Bounding box mouse down handler. Will determine if the mouse down</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* is on one of the spinner buttons, and increment/decrement the value</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* accordingly.</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* The method also sets up a timer, to support the user holding the mouse</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* down on the spinner buttons. The timer is cleared when a mouse up event</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* is detected.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li2"><div class="de2">_onMouseDown <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> node <span class="sy0">=</span> e.<span class="me1">target</span></div></li><li class="li1"><div class="de1">    ...</div></li><li class="li1"><div class="de1">    <span class="kw1">if</span> <span class="br0">&#40;</span>node.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;increment&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> currVal <span class="sy0">+</span> minorStep<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        ...</div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>node.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;decrement&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> currVal <span class="sy0">-</span> minorStep<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        ...</div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="kw1">if</span> <span class="br0">&#40;</span>handled<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">this</span>._setMouseDownTimers<span class="br0">&#40;</span>dir<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* Document mouse up handler. Clears the timers supporting</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* the &quot;mouse held down&quot; behavior.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li2"><div class="de2">_onDocMouseUp <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>._clearMouseDownTimers<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* Simple change handler, to make sure user does not input an invalid value</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">_onInputChange <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw1">this</span>._validateValue<span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">inputNode</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">// If the entered value is not valid, re-display the stored value</span></div></li><li class="li2"><div class="de2">        <span class="kw1">this</span>.<span class="me1">syncUI</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="coMULTI">/*
 * Bounding box Arrow up/down, Page up/down key listener.
 *
 * Increments/Decrements the spinner value, based on the key pressed.
 */</span>
_onDirectionKey <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    e.<span class="me1">preventDefault</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    ...
    <span class="kw1">switch</span> <span class="br0">&#40;</span>e.<span class="me1">charCode</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">case</span> <span class="nu0">38</span><span class="sy0">:</span>
            newVal <span class="sy0">+=</span> minorStep<span class="sy0">;</span>
            <span class="kw1">break</span><span class="sy0">;</span>
        <span class="kw1">case</span> <span class="nu0">40</span><span class="sy0">:</span>
            newVal <span class="sy0">-=</span> minorStep<span class="sy0">;</span>
            <span class="kw1">break</span><span class="sy0">;</span>
        <span class="kw1">case</span> <span class="nu0">33</span><span class="sy0">:</span>
            newVal <span class="sy0">+=</span> majorStep<span class="sy0">;</span>
            newVal <span class="sy0">=</span> Math.<span class="me1">min</span><span class="br0">&#40;</span>newVal<span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;max&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw1">break</span><span class="sy0">;</span>
        <span class="kw1">case</span> <span class="nu0">34</span><span class="sy0">:</span>
            newVal <span class="sy0">-=</span> majorStep<span class="sy0">;</span>
            newVal <span class="sy0">=</span> Math.<span class="me1">max</span><span class="br0">&#40;</span>newVal<span class="sy0">,</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;min&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw1">break</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">if</span> <span class="br0">&#40;</span>newVal <span class="sy0">!==</span> currVal<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> newVal<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * Bounding box mouse down handler. Will determine if the mouse down
 * is on one of the spinner buttons, and increment/decrement the value
 * accordingly.
 * 
 * The method also sets up a timer, to support the user holding the mouse
 * down on the spinner buttons. The timer is cleared when a mouse up event
 * is detected.
 */</span>
_onMouseDown <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> node <span class="sy0">=</span> e.<span class="me1">target</span>
    ...
    <span class="kw1">if</span> <span class="br0">&#40;</span>node.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;increment&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> currVal <span class="sy0">+</span> minorStep<span class="br0">&#41;</span><span class="sy0">;</span>
        ...
    <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>node.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;decrement&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span> currVal <span class="sy0">-</span> minorStep<span class="br0">&#41;</span><span class="sy0">;</span>
        ...
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">if</span> <span class="br0">&#40;</span>handled<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">this</span>._setMouseDownTimers<span class="br0">&#40;</span>dir<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * Document mouse up handler. Clears the timers supporting
 * the &quot;mouse held down&quot; behavior.
 */</span>
_onDocMouseUp <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">this</span>._clearMouseDownTimers<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
<span class="coMULTI">/*
 * Simple change handler, to make sure user does not input an invalid value
 */</span>
_onInputChange <span class="sy0">:</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw1">this</span>._validateValue<span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">inputNode</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">// If the entered value is not valid, re-display the stored value</span>
        <span class="kw1">this</span>.<span class="me1">syncUI</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div><textarea id="syntax-9a5761a8b5a3c5922607c033163c31b4-plain">/*
 * Bounding box Arrow up/down, Page up/down key listener.
 *
 * Increments/Decrements the spinner value, based on the key pressed.
 */
_onDirectionKey : function(e) {
    e.preventDefault();
    ...
    switch (e.charCode) {
        case 38:
            newVal += minorStep;
            break;
        case 40:
            newVal -= minorStep;
            break;
        case 33:
            newVal += majorStep;
            newVal = Math.min(newVal, this.get("max"));
            break;
        case 34:
            newVal -= majorStep;
            newVal = Math.max(newVal, this.get("min"));
            break;
    }

    if (newVal !== currVal) {
        this.set("value", newVal);
    }
},

/*
 * Bounding box mouse down handler. Will determine if the mouse down
 * is on one of the spinner buttons, and increment/decrement the value
 * accordingly.
 * 
 * The method also sets up a timer, to support the user holding the mouse
 * down on the spinner buttons. The timer is cleared when a mouse up event
 * is detected.
 */
_onMouseDown : function(e) {
    var node = e.target
    ...
    if (node.hasClass(this.getClassName("increment"))) {
        this.set("value", currVal + minorStep);
        ...
    } else if (node.hasClass(this.getClassName("decrement"))) {
        this.set("value", currVal - minorStep);
        ...
    }

    if (handled) {
        this._setMouseDownTimers(dir);
    }
},

/*
 * Document mouse up handler. Clears the timers supporting
 * the "mouse held down" behavior.
 */
_onDocMouseUp : function(e) {
    this._clearMouseDownTimers();
},

/*
 * Simple change handler, to make sure user does not input an invalid value
 */
_onInputChange : function(e) {
    if (!this._validateValue(this.inputNode.get("value"))) {
        // If the entered value is not valid, re-display the stored value
        this.syncUI();
    }
}</textarea></div>
<h4>ClassName Support Methods</h4>

<p>A key part of developing widgets which work with the DOM is defining class names which it will use to mark the nodes it renders. These class names could be used to mark a node for later retrieval/lookup, for CSS application (both functional as well as cosmetic) or to indicate the current state of the widget.</p>

<p>The widget infrastructure uses the <code>ClassNameManager</code> utility, to generate consistently named classes to apply to the nodes it adds to the page:</p>

<div id="syntax-0232ff574fb4a077f7aee2f73b2ae579" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">Y.<span class="me1">ClassNameManager</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span>Spinner.<span class="kw3">NAME</span><span class="sy0">,</span> <span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">...</div></li><li class="li1"><div class="de1"><span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;increment&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">Y.<span class="me1">ClassNameManager</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span>Spinner.<span class="kw3">NAME</span><span class="sy0">,</span> <span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
...
<span class="kw1">this</span>.<span class="me1">getClassName</span><span class="br0">&#40;</span><span class="st0">&quot;increment&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-0232ff574fb4a077f7aee2f73b2ae579-plain">Y.ClassNameManager.getClassName(Spinner.NAME, "value");
...
this.getClassName("increment");</textarea></div>
<p>
Class names generated by the Widget's <code>getClassName</code> prototype method use the NAME field of the widget, to generate a prefixed classname through <code>ClassNameManager</code> - e.g. for spinner the <code>this.getClassName("increment")</code> above will generate the class name <code>yui3-spinner-increment</code> ("yui" being the system level prefix, "spinner" being the widget name).
When you need to generate standard class names in static code (where you don't have a reference to <code>this.getClassName()</code>), you can use the ClassNameManager directly, as shown in line 1 above, to achieve the same results.
</p>

<h4>CSS Considerations</h4>

<p>Since widget uses the <code>getClassName</code> method to generate state-related class names and to mark the bounding box/content box of the widget (e.g. "yui3-[widgetname]-content", "yui3-[widgetname]-hidden", "yui3-[widgetname]-disabled"), we need to provide the default CSS handling for states we're interested in handling for the new Spinner widget. The "yui3-[widgetname]-hidden" class is probably one state class, which all widgets will provide implementations for.</p>

<div id="syntax-ba08a6982c308eb1ed4a5698fb45bf5f" class="yui-syntax-highlight"><div class="numbers"><pre class="css" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="coMULTI">/* Progressive enhancement support, to hide the text box, if JavaScript is enabled, while we instantiate the rich control */</span></div></li><li class="li1"><div class="de1"><span class="re1">.yui3-js-enabled</span> <span class="re1">.yui3-spinner-loading</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">display</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/* Controlling show/hide state using display (since this control is inline-block) */</span></div></li><li class="li1"><div class="de1"><span class="re1">.yui3-spinner-hidden</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">display</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/* Bounding Box - Set the bounding box to be &quot;inline block&quot; for spinner */</span></div></li><li class="li1"><div class="de1"><span class="re1">.yui3-spinner</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">display</span><span class="re2">:inline-</span>block<span class="sy0">;</span></div></li><li class="li1"><div class="de1">    zoom<span class="sy0">:</span><span class="nu0">1</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="sy0">*</span><span class="kw1">display</span><span class="sy0">:</span><span class="kw2">inline</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/* Content Box - Start adding visual treatment for the spinner */</span></div></li><li class="li1"><div class="de1"><span class="re1">.yui3-spinner-content</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">1px</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/* Input Text Box, generated through getClassName(&quot;value&quot;) */</span></div></li><li class="li1"><div class="de1"><span class="re1">.yui3-spinner-value</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    ...</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/* Button controls, generated through getClassName(&quot;increment&quot;) */</span></div></li><li class="li1"><div class="de1"><span class="re1">.yui3-spinner-increment</span><span class="sy0">,</span> <span class="re1">.yui3-spinner-decrement</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    ...</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="css" style="font-family:monospace;"><span class="coMULTI">/* Progressive enhancement support, to hide the text box, if JavaScript is enabled, while we instantiate the rich control */</span>
<span class="re1">.yui3-js-enabled</span> <span class="re1">.yui3-spinner-loading</span> <span class="br0">&#123;</span>
    <span class="kw1">display</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/* Controlling show/hide state using display (since this control is inline-block) */</span>
<span class="re1">.yui3-spinner-hidden</span> <span class="br0">&#123;</span>
    <span class="kw1">display</span><span class="sy0">:</span><span class="kw2">none</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/* Bounding Box - Set the bounding box to be &quot;inline block&quot; for spinner */</span>
<span class="re1">.yui3-spinner</span> <span class="br0">&#123;</span>
    <span class="kw1">display</span><span class="re2">:inline-</span>block<span class="sy0">;</span>
    zoom<span class="sy0">:</span><span class="nu0">1</span><span class="sy0">;</span>
    <span class="sy0">*</span><span class="kw1">display</span><span class="sy0">:</span><span class="kw2">inline</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/* Content Box - Start adding visual treatment for the spinner */</span>
<span class="re1">.yui3-spinner-content</span> <span class="br0">&#123;</span>
    <span class="kw1">padding</span><span class="sy0">:</span><span class="re3">1px</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/* Input Text Box, generated through getClassName(&quot;value&quot;) */</span>
<span class="re1">.yui3-spinner-value</span> <span class="br0">&#123;</span>
    ...
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/* Button controls, generated through getClassName(&quot;increment&quot;) */</span>
<span class="re1">.yui3-spinner-increment</span><span class="sy0">,</span> <span class="re1">.yui3-spinner-decrement</span> <span class="br0">&#123;</span>
    ...
<span class="br0">&#125;</span></pre></div><textarea id="syntax-ba08a6982c308eb1ed4a5698fb45bf5f-plain">/* Progressive enhancement support, to hide the text box, if JavaScript is enabled, while we instantiate the rich control */
.yui3-js-enabled .yui3-spinner-loading {
    display:none;
}

/* Controlling show/hide state using display (since this control is inline-block) */
.yui3-spinner-hidden {
    display:none;
}

/* Bounding Box - Set the bounding box to be "inline block" for spinner */
.yui3-spinner {
    display:inline-block;
    zoom:1;
    *display:inline;
}

/* Content Box - Start adding visual treatment for the spinner */
.yui3-spinner-content {
    padding:1px;
}

/* Input Text Box, generated through getClassName("value") */
.yui3-spinner-value {
    ...
}

/* Button controls, generated through getClassName("increment") */
.yui3-spinner-increment, .yui3-spinner-decrement {
    ...
}</textarea></div>
<h4>Using The Spinner Widget</h4>

<p>For the example, we have an input field already on the page, which we'd like to enhance to create a Spinner instance. We mark it with a yui3-spinner-loading class, so that if JavaScript is enabled, we can hide it while we're instantiating the rich control:</p>

<div id="syntax-d6fbf5f3ade8c8fcdc0a25c4b34571e4" class="yui-syntax-highlight"><div class="numbers"><pre class="html4strict" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;numberField&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;yui3-spinner-loading&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;20&quot;</span>&gt;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;numberField&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;yui3-spinner-loading&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;20&quot;</span>&gt;</span></pre></div><textarea id="syntax-d6fbf5f3ade8c8fcdc0a25c4b34571e4-plain"><input type="text" id="numberField" class="yui3-spinner-loading" value="20"></textarea></div>
<p>We provide the constructor for the Spinner with the <code>srcNode</code> which contains the input field with our initial value. The <code>HTML_PARSER</code> code we saw earlier will extract the value from the input field, and use it as the initial value for the Spinner instance:</p>

<div id="syntax-0b9500c9579632d9e1446c043a46c313" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="co1">// Create a new Spinner instance, drawing its </span></div></li><li class="li1"><div class="de1"><span class="co1">// starting value from an input field already on the </span></div></li><li class="li1"><div class="de1"><span class="co1">// page (the #numberField text input box)</span></div></li><li class="li1"><div class="de1"><span class="kw2">var</span> spinner <span class="sy0">=</span> <span class="kw2">new</span> Spinner<span class="br0">&#40;</span><span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">    srcNode<span class="sy0">:</span> <span class="st0">&quot;#numberField&quot;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    max<span class="sy0">:</span><span class="nu0">100</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    min<span class="sy0">:</span><span class="nu0">0</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">spinner.<span class="me1">render</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">spinner.<span class="kw3">focus</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="co1">// Create a new Spinner instance, drawing its </span>
<span class="co1">// starting value from an input field already on the </span>
<span class="co1">// page (the #numberField text input box)</span>
<span class="kw2">var</span> spinner <span class="sy0">=</span> <span class="kw2">new</span> Spinner<span class="br0">&#40;</span><span class="br0">&#123;</span>
    srcNode<span class="sy0">:</span> <span class="st0">&quot;#numberField&quot;</span><span class="sy0">,</span>
    max<span class="sy0">:</span><span class="nu0">100</span><span class="sy0">,</span>
    min<span class="sy0">:</span><span class="nu0">0</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
spinner.<span class="me1">render</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
spinner.<span class="kw3">focus</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-0b9500c9579632d9e1446c043a46c313-plain">// Create a new Spinner instance, drawing its 
// starting value from an input field already on the 
// page (the #numberField text input box)
var spinner = new Spinner({
    srcNode: "#numberField",
    max:100,
    min:0
});
spinner.render();
spinner.focus();</textarea></div>
<p>The custom widget class structure discussed above is captured in this <a href="assets/mywidget.js.txt">"MyWidget" template file</a>, which you can use as a starting point to develop your own widgets.</p>
				</div>
				<div class="yui-u sidebar">
	
					<div id="examples" class="mod box4">
                        <div class="hd">
						<h4>
    Widget Examples:</h4>
                        </div>
						<div class="bd">
							<ul>
								<li class='selected'><a href='../widget/widget-extend.html'>Extending the Base Widget Class</a></li><li><a href='../widget/widget-build.html'>Creating Custom Widget Classes</a></li><li><a href='../widget/widget-plugin.html'>Creating a Widget Plugin</a></li><li><a href='../widget/widget-tooltip.html'>Creating a Simple Tooltip Widget</a></li><li><a href='../widget/widget-parentchild-listbox.html'>Creating a Hierarchical ListBox Widget</a></li>							</ul>
						</div>
					</div>

					<div class="mod box4">
                        <div class="hd">
						<h4>More Widget Resources:</h4>
                        </div>
                        <div class="bd">
						<ul>
							<!-- <li><a href="http://developer.yahoo.com/yui/widget/">User's Guide</a> (external)</li> -->
<li><a href="../../api/module_widget.html">API Documentation</a></li></ul>
                        </div>
					</div>
			  </div>
		</div>

		</div>
	</div>


<div class="yui-b toc3" id="tocWrapper">
<!-- TABLE OF CONTENTS -->
<div id="toc">
	
<ul>
<li class="sect first">YUI 3 Resources</li><li class="item"><a title="YUI 3 -- Yahoo! User Interface (YUI) Library" href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="YUI 3 Dependency Configurator -- configure your custom YUI implementation" href="http://developer.yahoo.com/yui/3/configurator/index.html">YUI 3 Dependency Configurator</a></li><li class="item"><a title="The YUI 3 Forum on YUILibrary.com" href="http://yuilibrary.com/forum/viewforum.php?f=15">YUI 3 Forums (external)</a></li><li class="item"><a title="Found a bug or a missing feature? Let us know on YUILibrary.com." href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/license.html">YUI License</a></li><li class="item"><a title="Download and fork the YUI project on GitHub" href="http://github.com/yui">YUI on Github</a></li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI Global Object - Functional Examples" href="../../examples/yui/index.html">YUI Global Object</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin</a></li><li class="selected "><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="AsyncQueue - Functional Examples" href="../../examples/async-queue/index.html">AsyncQueue</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Drag &amp; Drop - Functional Examples" href="../../examples/dd/index.html">Drag &amp; Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="History - Functional Examples" href="../../examples/history/index.html">History <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="Internationalization - Functional Examples" href="../../examples/intl/index.html">Internationalization</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="JSONP (JSON with Padding) - Functional Examples" href="../../examples/jsonp/index.html">JSONP <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Recordset - Functional Examples" href="../../examples/recordset/index.html">Recordset <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Resize - Functional Examples" href="../../examples/resize/index.html">Resize <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Sortable - Functional Examples" href="../../examples/sortable/index.html">Sortable <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="item"><a title="Transition - Functional Examples" href="../../examples/transition/index.html">Transition <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Uploader - Functional Examples" href="../../examples/uploader/index.html">Uploader <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="YQL Query - Functional Examples" href="../../examples/yql/index.html">YQL Query <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="item"><a title="AutoComplete - Functional Examples" href="../../examples/autocomplete/index.html">AutoComplete <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Charts - Functional Examples" href="../../examples/charts/index.html">Charts <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataTable - Functional Examples" href="../../examples/datatable/index.html">DataTable <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Dial - Functional Examples" href="../../examples/dial/index.html">Dial <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Editor - Functional Examples" href="../../examples/editor/index.html">Editor <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="ScrollView - Functional Examples" href="../../examples/scrollview/index.html">ScrollView <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="TabView - Functional Examples" href="../../examples/tabview/index.html">TabView <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Grids - Functional Examples" href="../../examples/cssgrids/index.html">CSS Grids <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Console Filters Plugin- Functional Examples" href="../../examples/console-filters/index.html">Plugin.ConsoleFilters <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">Other Useful YUI 3 Resources</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li></ul>
</div>
</div>
	</div><!--closes bd-->

	<div id="ft">
        <p class="first">Copyright &copy; 2011 Yahoo! Inc. All rights reserved.</p>
        <p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - 
            <a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - 
            <a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - 
            <a href="http://careers.yahoo.com/">Job Openings</a></p>
	</div>
</div>
<script language="javascript"> 
var yuiConfig = { filter: 'raw' };
</script>
<script src="../../assets/syntax.js"></script>
<script src="../../assets/dpSyntaxHighlighter.js"></script>
<script language="javascript"> 
dp.SyntaxHighlighter.HighlightAll('code'); 
</script>
</body>
</html>
